package week5;

import java.util.HashSet;
import java.util.Set;

public class Ex44 {
    public static void main(String[] args) {
        Set<Integer> list = new HashSet<>();
        for (int i = 1; i <= 5000; ++i){
            list.add(i * (3*i-1) / 2);
        }
        for (int i = 1; i <= list.size(); ++i){
            for (int j = 1; j <= i; ++j){
                if (list.contains(i * (3*i-1) / 2 + j * (3*j-1) / 2) && list.contains(i * (3*i-1) / 2 - j * (3*j-1) / 2)){
                    System.out.println(i * (3*i-1) / 2 - j * (3*j-1) / 2);
                    return;
                }
            }
        }

    }
}
